﻿/*
 * This file is part of CommunitySettlers.
 *
 * CommunitySettlers is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * CommunitySettlers is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with CommunitySettlers.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Author: Christoph Husse
 * 
 * Also checkout our homepage: http://communitysettlers.codeplex.com/
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace SettlersEngine
{
    internal partial class RuntimeGrid
    {
        internal void AddOneCycle()
        {
            m_MovableManager.AddOneCycle();
        }

        internal void SetMovablePath(IMovableObject inMovable, Point inTarget)
        {
            if (!Bounds.Contains(inTarget))
                throw new ArgumentOutOfRangeException();

            m_MovableManager.SetPath(inMovable, inTarget);
        }

        

        internal bool DisturbeAt(CyclePoint inPosition, Int32 inRange)
        {
            Boolean result = false;

            for (int x = 0; x < inRange; x++)
            {
                for (int y = 0; y < inRange; y++)
                {
                    IMovableObject movable = m_Cells[inPosition.XGrid + x, inPosition.YGrid + y].FixedObject as IMovableObject;

                    if (movable != null)
                    {
                        Point pathTarget = new Point(
                            Math.Max(0, Math.Min(Width - 1, m_Random.Next(-3,3))),
                            Math.Max(0, Math.Min(Height - 1, m_Random.Next(-3,3))));
                        
                        // setup path
                        SetMovablePath(movable, pathTarget);

                        result = true;
                    }
                }
            }

            return result;
        }
    }
}
